<?php

namespace Admin\Controller;

use Think\Controller;

/**
 * 客服临时任务
 */
class GoTravelController extends CommonController
{

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 用户列表
     */
    public function user_list()
    {
        $this->display();
        die;
    }

//
//    /**
//     * 注册未认证列表
//     */
//    public function noCertList()
//    {
//        $n = I('page', 0);
//        $num = 10;
//        $page = ($n - 1) * 10;
//        $where = [];
//        $where['a.type'] = 3;//属于注册未认证
//        if ($_SESSION['role_id'] == '2') {
//            $where['a.admin_id'] = $_SESSION['id'];
//        }
//        $where['b.cert_status'] = 1;
//        $field = 'b.mobile,b.vid,b.truename,b.ctime,b.sex';
//        $count = M('kefu_ownuser', '', 'KEFU_R')->join('a join dxd_user.user b on a.vid =b.vid and b.type=3')->where($where)->count();
//        $data = M('kefu_ownuser', '', 'KEFU_R')->join('a join dxd_user.user b on a.vid =b.vid and b.type=3')->where($where)->order('a.id desc')->field($field)->limit($page, $num)->select();
//        foreach ($data as $k => $v) {
//            $data[$k]['ctime'] = date('Y-m-d H:i:s', $v['ctime']);
//            if ($v['sex'] == 1) {
//                $data[$k]['sex'] = '男';
//            } else if ($v['sex'] == 2) {
//                $data[$k]['sex'] = '女';
//            } else {
//                $data[$k]['sex'] = '未知';
//            }
//            $data[$k]['user_mobile'] = get_mobile($v['mobile']);
//            //最近备注
//            $content = M('call_info', '', 'KEFU_R')->where(['vid' => $v['vid']])->order('ctime desc')->limit(1)->field('content')->find();
//            if (empty($content['content'])) {
//                $data[$k]['mark'] = '--';
//            } else {
//                $data[$k]['mark'] = $content['content'];
//            }
//            if (empty($v['truename'])) {
//                $data[$k]['truename'] = '---';
//            }
//        }
//        $count = intval($count);
//        $tol = ceil($count / $num);
//        $this->ajaxReturn(array('code' => '1001', 'result' => 'success', 'count' => $count, 'tol' => $tol, 'data' => $data));
//    }

    /**
     * @param:
     * @param:注册未认证
     */
    public function noCertList()
    {
        $n = I('page', 0);
        $num = 10;
        $page = ($n - 1) * 10;
        $where['cert_status'] = 1;
        $where['type'] = 3;
        $field = 'mobile,vid,truename,ctime,sex';
        $count = M('user', '', 'KEFU_R')->where($where)->count();
        $data = M('user', '', 'KEFU_R')->where($where)->order('id desc')->field($field)->limit($page, $num)->select();
        foreach ($data as $k => $v) {
            $data[$k]['ctime'] = date('Y-m-d H:i:s', $v['ctime']);
            if ($v['sex'] == 1) {
                $data[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $data[$k]['sex'] = '女';
            } else {
                $data[$k]['sex'] = '未知';
            }
            $data[$k]['user_mobile'] = get_mobile($v['mobile']);
            //最近备注
            $content = M('call_info', '', 'KEFU_R')->where(['vid' => $v['vid']])->order('ctime desc')->limit(1)->field('content')->find();
            if (empty($content['content'])) {
                $data[$k]['mark'] = '--';
            } else {
                $data[$k]['mark'] = $content['content'];
            }
            if (empty($v['truename'])) {
                $data[$k]['truename'] = '---';
            }
        }
        $count = intval($count);
        $tol = ceil($count / $num);
        $this->ajaxReturn(array('code' => '1001', 'result' => 'success', 'count' => $count, 'tol' => $tol, 'data' => $data));



    }
    /**
     * 回复记录 显示
     */
    public function mark()
    {
        $mobile = I('mobile');
        $type = I('type');
        switch ($type) {
            case '1';
                $data = M('user_surve_mark', '', 'KEFU')->where(['mobile' => $mobile, 'type' => 4])->field('content,admin_name,ctime')->select();
                foreach ($data as $k => $v) {
                    $data[$k]['ctime'] = date('Y-m-d H:i:s', $v['ctime']);
                }
                break;
            case '2';
                $vid = M('user', '', 'USER_R')->where(['mobile' => $mobile])->getfield('vid');
                $where['ctime'] = array('egt', strtotime(date('Y-m-d', time())));
                $where['vid'] = $vid;
                $data = M('temp_today_pay_mark', '', 'KEFU')->where($where)->field('reason as content,name as admin_name,ctime')->select();
                foreach ($data as $k => $v) {
                    $data[$k]['ctime'] = date('Y-m-d H:i:s', $v['ctime']);
                }

                break;
        }
        $this->assign(array('data' => $data, 'mobile' => $mobile, 'type' => $type));
        $this->display();
    }


    /**
     * 回复记录
     */
    public function add_mark()
    {
        $mobile = I('mobile');
        $info = I('info');
        $type = I('type');
        switch ($type) {
            case '1':
                //加入记录表，type==4空号调查
                M('cl_mobile_status_detail', '', 'KEFU_FK')->startTrans();
                M('user_surve_mark', '', 'KEFU')->startTrans();
                $arr = array('admin_name' => $_SESSION['name'], 'content' => $info, 'mobile' => $mobile, 'type' => 4, 'ctime' => time());
                $update = M('cl_mobile_status_detail', '', 'KEFU_FK')->where(['mobile' => $mobile])->setField('research_result', $info);
                $add = M('user_surve_mark', '', 'KEFU')->add($arr);
                if ($add && $update) {
                    M('cl_mobile_status_detail', '', 'KEFU_FK')->commit();
                    M('user_surve_mark', '', 'KEFU')->commit();
                    add_log('空号检测备注' . $add);
                    $this->ajaxReturn(array('code' => '1001', 'result' => '添加成功'));
                } else {
                    M('cl_mobile_status_detail', '', 'KEFU_FK')->rollback();
                    M('user_surve_mark', '', 'KEFU')->rollback();
                    $this->ajaxReturn(array('code' => '1002', 'result' => '添加失败'));
                }

                break;
            case 2:
                $vid = M('user', '', 'USER_R')->where(['mobile' => $mobile])->getfield('vid');
                $arr = array('vid' => $vid, 'reason' => $info, 'ctime' => time(), 'name' => $_SESSION['name']);
                $add = M('temp_today_pay_mark', '', 'KEFU')->add($arr);
                if ($add) {
                    add_log('今日需还款用户通知备注' . $add);
                    $this->ajaxReturn(array('code' => '1001', 'result' => '备注成功'));
                } else {
                    $this->ajaxReturn(array('code' => '1002', 'result' => '备注失败'));
                }
                break;
        }
    }



}
